home *** CD-ROM | disk | FTP | other *** search
- /*
- * @(#)display.c 1.7 3/16/88
- */
- #include "assert.h"
- #include "nodes.h"
- #include "MyParser.h"
- #include "opNames.h"
- #include "map.h"
- #include "sequence.h"
- #include "environment.h"
- #include "system.h"
-
- static char *BLANKS = " ";
- static char *TABS = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
-
- #define Indent(File, N) fprintf(File, "%.*s%.*s",\
- (N) >> 3, TABS, (N) & 07, BLANKS)
- #define NLIndent(File, N) fprintf(File, "\n%.*s%.*s",\
- (N) >> 3, TABS, (N) & 07, BLANKS)
-
- static Map displayMap = NULL;
- static void rDisplayTree(), inner_rDisplaySymbol();
- static int vLevel;
-
- void DisplayTree(fp, t, verboseLevel, maxLevel)
- FILE *fp;
- NodePtr t;
- int verboseLevel, maxLevel;
- {
- displayMap = Map_Create();
- vLevel = verboseLevel;
- rDisplayTree(fp, t, 0, maxLevel);
- fprintf(fp, "\n");
- if (fflush(fp) == EOF) assert(FALSE);
- Map_Destroy(displayMap);
- }
-
- extern char *addressToString();
-
- static void inner_rDisplaySymbol(fp, s, indent, maxLevel)
- FILE *fp;
- register Symbol s;
- int indent, maxLevel;
- {
- if (s == NULL) {
- fprintf(fp, " NULL");
- return;
- }
- if (Map_Lookup(displayMap, (int)s) != NIL) {
- fprintf(fp, " Symbol *0x%x %s%s%s", s, ST_KindName[(int)s->itsKind],
- s->isManifest ? " (iM)" : "", s->hasValue ? " (hV)" : "");
- return;
- } else {
- Map_Insert(displayMap, (int)s, 1);
- fprintf(fp, " Symbol 0x%x %s%s%s", s, ST_KindName[(int)s->itsKind],
- s->isManifest ? " (iM)" : "", s->hasValue ? " (hV)" : "");
- NLIndent(fp, indent);
- fprintf(fp, "address = %s", addressToString(s->v.address));
- if (vLevel > 0) {
- NLIndent(fp, indent);
- fprintf(fp, "AT ");
- rDisplayTree(fp, s->value.ATinfo, indent+3, maxLevel);
- NLIndent(fp, indent);
- fprintf(fp, "CT ");
- rDisplayTree(fp, s->value.CTinfo, indent+3, maxLevel);
- NLIndent(fp, indent);
- fprintf(fp, "V ");
- rDisplayTree(fp, s->value.value, indent+3, maxLevel);
- }
- }
- }
-
- #define rDisplaySymbol(fp, sn, indent, maxLevel) inner_rDisplaySymbol(fp, \
- (sn) == 0 ? NULL : ST_Fetch(sn), indent, maxLevel)
-
- static void rDisplayTree(fp, t, indent, maxLevel)
- FILE *fp;
- NodePtr t;
- int indent;
- int maxLevel;
- {
- register int i;
- Symbol st;
-
- maxLevel --;
- if (t == NULL) {
- fprintf(fp, "NULL");
- } else if ((int)t < 0x200) {
- /* it is probably an input token */
- fprintf(fp, " Input token \"%s\" (%d)", TOKENNAME(t), (int)t);
- } else if (Map_Lookup(displayMap, (int)t) != NIL) {
- fprintf(fp, "*0x%x %s", t, tagNames[(int)t->tag]);
- switch (t->tag) {
- case T_IDENT:
- fprintf(fp, " \"%s\" (%d)", Ident_Name(t->b.ident.ident),
- t->b.ident.ident);
- break;
- case P_BUILTINLIT:
- fprintf(fp, " \"%s\" (%d)",
- TOKENNAME(t->b.builtinlit.whichType),
- t->b.builtinlit.whichType);
- break;
- case P_BOOLLIT:
- fprintf(fp, " \"%s\"",
- t->b.boollit.value ? "true" : "false");
- break;
- case P_GLOBALREF:
- fprintf(fp, " id = 0x%x", t->b.globalref.id);
- break;
- case P_SYMREF:
- case P_SYMDEF:
- case P_SYMBOL:
- if (t->tag == P_SYMBOL) {
- st = (Symbol) t;
- } else {
- st = t->b.symref.symbol;
- }
- fprintf(fp, " \"%s\" #%d",
- st == NULL ? Ident_Name(t->b.symref.ident) : ST_SymbolName(st),
- st == NULL ? -1 : st->itsSymbolNumber);
- break;
- case P_ATLIT:
- case P_OBLIT:
- if (t->b.atlit.f.immutable) fprintf(fp, " (immutable)");
- if (t->b.atlit.f.writeSeparately) fprintf(fp, " (wS)");
- if (t->b.atlit.f.isTypeVariable) fprintf(fp, " (tV)");
- if (t->b.atlit.f.dependsOnTypeVariable) fprintf(fp, " (dTV)");
- if (t->b.atlit.f.inExecutableConstruct) fprintf(fp, " (iEC)");
- if (t->b.atlit.f.isManifest) fprintf(fp, " (iM)");
- if (t->b.atlit.f.typesAreAssigned) fprintf(fp, " (tAA)");
- if (t->b.atlit.f.typesHaveBeenChecked) fprintf(fp, " (tHBC)");
- if (t->b.atlit.id != 0) fprintf(fp, " (%08x)", t->b.atlit.id);
- if (getCodeOID(t) != 0) fprintf(fp, " code oid = 0x%x",getCodeOID(t));
- break;
- case P_OPSIG:
- if (t->b.opsig.isFunction) fprintf(fp, " (function)");
- break;
- case P_OPNAME:
- fprintf(fp, " %x %s",
- t->b.opname.id,
- t->b.opname.id == 0 ?
- Ident_Name(t->b.opname.ident) :
- ON_Name(t->b.opname.id));
- break;
- default:
- break;
- }
- return;
- } else {
- Map_Insert(displayMap, (int)t, 1);
- fprintf(fp, " 0x%x %s", t, tagNames[(int)t->tag]);
- switch (t->tag) {
- case T_STRING:
- case P_STRINGLIT:
- case P_CHARLIT:
- case P_INTLIT:
- case P_REALLIT:
- fprintf(fp, " \"%s\"", t->b.string.string);
- break;
- case T_IDENT:
- fprintf(fp, " \"%s\" (%d)", Ident_Name(t->b.ident.ident),
- t->b.ident.ident);
- break;
- case P_BUILTINLIT:
- fprintf(fp, " \"%s\" (%d)",
- TOKENNAME(t->b.builtinlit.whichType),
- t->b.builtinlit.whichType);
- break;
- case P_BOOLLIT:
- fprintf(fp, " \"%s\"",
- t->b.boollit.value ? "true" : "false");
- break;
- case P_FIELDREF:
- fprintf(fp, " \"%s\"",
- Ident_Name(t->b.fieldref.ident));
- break;
- case P_GLOBALREF:
- fprintf(fp, " id = 0x%x", t->b.globalref.id);
- if (vLevel > 2) {
- NLIndent(fp, indent);
- fprintf(fp, "v");
- resolveGlobal(t, (ValuePtr)NULL);
- rDisplayTree(fp, t->b.globalref.value, indent+1, maxLevel);
- }
- break;
- case P_SYMREF:
- case P_SYMDEF:
- case P_SYMBOL:
- if (t->tag == P_SYMBOL) {
- st = (Symbol) t;
- } else {
- st = t->b.symref.symbol;
- }
- fprintf(fp, " \"%s\" #%d",
- st == NULL ? Ident_Name(t->b.symref.ident) : ST_SymbolName(st),
- st == NULL ? -1 : st->itsSymbolNumber);
- NLIndent(fp, indent+1);
- rDisplaySymbol(fp, st, indent+1, maxLevel);
- break;
- case P_ATLIT:
- case P_OBLIT:
- if (t->b.atlit.f.immutable) fprintf(fp, " (immutable)");
- if (t->b.atlit.f.writeSeparately) fprintf(fp, " (wS)");
- if (t->b.atlit.f.isTypeVariable) fprintf(fp, " (tV)");
- if (t->b.atlit.f.dependsOnTypeVariable) fprintf(fp, " (dTV)");
- if (t->b.atlit.f.inExecutableConstruct) fprintf(fp, " (iEC)");
- if (t->b.atlit.f.isManifest) fprintf(fp, " (iM)");
- if (t->b.atlit.f.typesAreAssigned) fprintf(fp, " (tAA)");
- if (t->b.atlit.f.typesHaveBeenChecked) fprintf(fp, " (tHBC)");
- if (t->b.atlit.id != 0) fprintf(fp, " (%08x)", t->b.atlit.id);
- if (getCodeOID(t) != 0) fprintf(fp, " code oid = 0x%x",getCodeOID(t));
- if (t->b.atlit.f.isManifest && (t->b.atlit.id & 0xffffff) <= (OID)0x000100)
- return;
- break;
- case P_OPSIG:
- if (t->b.opsig.isFunction == FALSE) ;
- else if (t->b.opsig.isFunction == TRUE)
- fprintf(fp, " (function)");
- else fprintf(fp, " (garbage)");
- break;
- case P_OPNAME:
- fprintf(fp, " %x %s",
- t->b.opname.id,
- t->b.opname.id == 0 ?
- Ident_Name(t->b.opname.ident) :
- ON_Name(t->b.opname.id));
- break;
- case P_PARAM:
- case P_ARG:
- if (t->b.param.move) fprintf(fp, " move");
- break;
- default:
- break;
- }
- if (maxLevel <= 0) return;
- if (t->tag == P_SYMBOL) return;
- for (i = t->firstChild; i < t->nChildren; i++) {
- NLIndent(fp, indent);
- fprintf(fp, "%c", i < 10 ? i + '0' : i < 36 ? i + 'a' - 10 :
- i < 62 ? i + 'A' - 36 : '*');
- rDisplayTree(fp, t->b.children[i], indent+1, maxLevel);
- }
- }
- }
-
- void ShowTree(t, verboseLevel, maxLevel)
- int t;
- int verboseLevel;
- int maxLevel;
- {
- DisplayTree(stdout, (NodePtr)t, verboseLevel, maxLevel);
- }
-
- #define NBUFFERS 8
- static char buffers[NBUFFERS][132];
- static int lastBuffer = NBUFFERS-1;
- #define NEXTBUFFER() (buffers[((++lastBuffer) % NBUFFERS)])
-
- char *showExpression(t)
- NodePtr t;
- {
- char *buffer = NEXTBUFFER();
- if (t == NN) {
- sprintf(buffer, "NULL");
- } else if ((int)t <= 0x200) {
- sprintf(buffer, "%s", TOKENNAME(t));
- } else {
- switch (t->tag) {
- case P_SYMREF:
- sprintf(buffer, "%s",
- t->b.symref.symbol == NULL ?
- Ident_Name(t->b.symref.ident) :
- ST_SymbolName(t->b.symref.symbol));
- break;
- case P_BUILTINLIT:
- sprintf(buffer, "%s", TOKENNAME(t->b.builtinlit.whichType));
- break;
- case P_INVOC:
- sprintf(buffer, "??.%s%s", t->b.invoc.opname->b.opname.id == 0 ?
- Ident_Name(t->b.invoc.opname->b.opname.ident) :
- ON_Name(t->b.invoc.opname->b.opname.id),
- t->b.invoc.args == NULL ? "" : "[??]");
- break;
- default:
- sprintf(buffer, "unknown");
- break;
- }
- }
- return(buffer);
- }
-
- char *showInvoc(t)
- NodePtr t;
- {
- char *buffer = NEXTBUFFER(), *b;
- assert(t->tag == P_INVOC);
- b = showExpression(t->b.invoc.target);
- strcpy(buffer, b);
- strcat(buffer, ".");
- strcat(buffer, t->b.invoc.opname->b.opname.id == 0 ?
- Ident_Name(t->b.invoc.opname->b.opname.ident) :
- ON_Name(t->b.invoc.opname->b.opname.id));
- return(buffer);
- }
-
- char *NameOf(p)
- register NodePtr p;
- {
- register Symbol st;
- st = p->b.atlit.name->b.symdef.symbol;
- return(ST_SymbolName(st));
- }
-
-
- char *ATName(p)
- register NodePtr p;
- {
- register Symbol st;
- NodePtr q;
- char *sp = NEXTBUFFER();
- if (p == NULL) {
- strcpy(sp, "<unknown>");
- } else if (p->tag == T_SEQUENCE) {
- strcpy(sp, "{ ");
- Sequence_For(q, p)
- if (z__z > 0) strcat(sp, ", ");
- strcat(sp, ATName(q));
- Sequence_Next
- strcat(sp, " }");
- } else {
- st = p->b.atlit.name->b.symdef.symbol;
- sprintf(sp, "\"%s\" (0x%08x)", ST_SymbolName(st), p->b.atlit.id);
- }
- return(sp);
- }
-
- char *STName(st)
- register Symbol st;
- {
- char *sp = NEXTBUFFER();
- sprintf(sp, "\"%s\" (%08x)", ST_SymbolName(st), st);
- return(sp);
- }
-
- char *SigName(p)
- NodePtr p;
- {
- return(ON_Name((p)->b.opsig.name->b.opname.id));
- }
-
- void ShowExpression(t)
- int t;
- {
- fprintf(stdout, "%s\n", showExpression((NodePtr)t));
- }
-
- void ShowInvoc(t)
- int t;
- {
- fprintf(stdout, "%s\n", showInvoc((NodePtr)t));
- }
-